//
// Created by fengg on 2020/2/26.
//

#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;

class Multinomial {
public:
    int maxTimes;
    double *sequence;
    Multinomial(int maxTimes){
        this->maxTimes = maxTimes;
        sequence = (double *) malloc(sizeof(double)*(maxTimes+1));
    }

    double get(int times){
        if (times > this->maxTimes)
            return 0.0;
        return this->sequence[times];
    }


};

Multinomial operator+= (Multinomial x,Multinomial y){
    int loopCount = x.maxTimes > y.maxTimes ? y.maxTimes : x.maxTimes;
    for (int i = 0; i <= loopCount; ++i) {
        x.sequence[i] += y.sequence[i];
    }
    return x;
}

istream& operator>>(istream& is,Multinomial *x){
    for (int i = x->maxTimes; i >= 0 ; --i) {
        is >> x->sequence[i];
    }
    return is;
}

ostream& operator<<(ostream& os,Multinomial *x){
    bool header = true;
    for (int i = x->maxTimes; i >= 0; --i) {
        if(x->sequence[i] == 0)
            continue;
        if(!header){
            if (x->sequence[i] == 1)
                os << '+';
            os << setiosflags(ios::showpos);

        } else {
            header = false;
        }
        switch ((int) x->sequence[i]){
            case -1:
                os << '-';
                break;
            case 1:
                break;
            default:
                os << x->sequence[i];
        }

        os << resetiosflags(ios::showpos);
        if (i > 1)
            os <<"x^" << i;
        else if(i == 1)
            os << 'x';
    }
    if (header){
        os << 0;
    }
    os << endl;
    return os;
}

int main(){
    Multinomial *x,*y;
    int maxTimes=0;

    cin >> maxTimes;
    x = new Multinomial(maxTimes);
    cin >> x;

    cin >> maxTimes;
    y = new Multinomial(maxTimes);
    cin >> y;

    *x += *y;

    cout << x;

    return 0;
}